<!DOCTYPE html>
<script src="../include.js"></script>
<div id="a" contenteditable>foobar</div>
<div id="b" contenteditable>a&nbsp;&nbsp;&nbsp;</div>
<div id="c" contenteditable>a&nbsp;&nbsp;b</div>
<div id="d" contenteditable>a&nbsp;&nbsp;&nbsp;b</div>
<div id="e" contenteditable>a&nbsp;&nbsp;&nbsp;&nbsp;b</div>
<div id="f" contenteditable>a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b</div>
<div id="g" contenteditable>&nbsp;&nbsp;b</div>
<div id="h" contenteditable>foo👩🏼‍❤️‍👨🏻bar</div>
<div id="i" contenteditable>foo<div>bar<br>baz</div></div>
<script>
    test(() => {
        const testForwardDelete = function(divId, anchorExpression, start, end = start) {
            println(`--- ${divId} ---`);
            const divElm = document.querySelector(`div#${divId}`);
            println(`Before: ${divElm.innerHTML}`);

            // Place cursor
            const anchor = anchorExpression(divElm);
            getSelection().setBaseAndExtent(anchor, start, anchor, end);

            // Press delete
            document.execCommand("forwardDelete");

            println(`After: ${divElm.innerHTML}`);
        };

        testForwardDelete("a", (node) => node.firstChild, 3);
        testForwardDelete("b", (node) => node.firstChild, 1);
        testForwardDelete("c", (node) => node.firstChild, 1);
        testForwardDelete("d", (node) => node.firstChild, 1);
        testForwardDelete("e", (node) => node.firstChild, 1);
        testForwardDelete("f", (node) => node.firstChild, 1);
        testForwardDelete("g", (node) => node.firstChild, 0);
        testForwardDelete("h", (node) => node.firstChild, 3);
        testForwardDelete("i", (node) => node.firstChild, 3);
    });
</script>
